<template>
  <div>
    <el-form ref="form" label-width="140px" style="overflow: hidden">
      <el-row>
        <el-col :span="12">
          <el-form-item label="前缀">
            {{ curEnterprise.prefix }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="企业名称">
            {{ curEnterprise.entName }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="企业类型">
            {{ curEnterprise.businessCode | entTypeMapFilter }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属行业">
            {{ curEnterprise.businessName }}
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="注册所在地">
            {{ curEnterprise.areaName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="详细地址">
            {{ curEnterprise.address }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="官方网站">
            {{ curEnterprise.webSite }}
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>

    <el-image-viewer v-if="showMask" :on-close="closeViewer" :url-list="srcList" />
    <!--<el-dialog
      title="图片详情"
      :visible.sync="showMask"
      center append-to-body>
      <el-image :src="curImg" alt="" @click="showMask=true" class="showClickImg" style="width:100%" :preview-src-list="srcList"></el-image>
    </el-dialog>-->
  </div>
</template>
<script>
/* eslint-disable vue/no-unused-components */

import MyDiv from '@/components/MyDiv'
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
import { detail, enterpriseDetail } from '@/api/enterprise'
import { idCardType, entCardType, entTypeMap, entCrtImgType } from '@/utils/constant'
import { get } from '@/utils/request'

export default {
  name: 'EntDetail',
  filters: {
    idTypeFilter(type) {
      return idCardType[type]
    },
    entTypeFilter(type) {
      let nowName
      entCardType.forEach((item, index) => {
        if (item.key == type) {
          nowName = item.value
        }
      })
      console.log(nowName)
      return nowName
    },
    entTypeMapFilter(type) {
      return entTypeMap[type]
    },
    entImgTypeFilter(type) {
      return entCrtImgType[type]
    }
  },
  components: { MyDiv, ElImageViewer },
  props: {
    enterpriseId: String,
    isEnterprise: Number
  },
  data() {
    return {
      curEnterprise: {},
      showMask: false,
      curImg: '',
      srcList: []
    }
  },
  inject: {
    elForm: {
      default: ''
    },
    elFormItem: {
      default: ''
    }
  },
  computed: {

  },
  watch: {
    enterpriseId: function() {
      this.initDetail()
    }
  },
  mounted() {
    this.initDetail()
  },
  methods: {
    initDetail() {
      console.log(this.isEnterprise)
      if (this.isEnterprise) {
        enterpriseDetail(this.enterpriseId).then(res => {
          console.log(res)
          this.curEnterprise = res
          // this.initPrefixList()
        })
      } else {
        detail(this.enterpriseId).then(res => {
          console.log(res)
          this.curEnterprise = res
          // this.initPrefixList()
        })
      }
    },
    initPrefixList() {
      get('/ht/prefixListByEnterpriseId.json', { 'enterpriseId': this.enterpriseId }).then(res => {
        let prefixString = ''
        res.forEach(item => {
          prefixString += item + ','
        })
        prefixString = prefixString.substr(0, prefixString.length - 1)
        this.curEnterprise.prefix = prefixString
      })
    },
    showImg(event) {
      this.srcList = []
      var mUrl = event.target.src
      this.showMask = true
      this.curImg = mUrl
      this.srcList.push(mUrl)
    },
    closeViewer() {
      this.showMask = false
    }
  }
}
</script>

<style scoped>
  .el-form-item{
    margin-bottom: 0;
  }
  /*.el-form-item{*/
  /*  width: 50%;*/
  /*  float: left;*/
  /*}*/

  /*.el-divider{*/
  /*  float: left;*/
  /*}*/
</style>
